package cjq.demo.thread.ch6_5;

import java.util.Date;
import java.util.concurrent.DelayQueue;

/**
 * Created by Administrator on 2016/5/4.
 */
public class Task implements Runnable {
    private int id;
    private DelayQueue<Event> queue;

    public Task(int id,DelayQueue<Event> queue){
        this.id=id;
        this.queue = queue;
    }

    public void run(){
        Date now = new Date();
        Date delay = new Date();

        delay.setTime(now.getTime()+(id*1000));
        System.out.println("Thread: "+id+" : "+delay);

        for (int i = 0; i < 100; i++) {
            Event event = new Event(delay);
            queue.add(event);
        }
    }
}
